package com.easylinkin.linkappapi.grid.controller;

import com.easylinkin.linkappapi.grid.models.dto.GridInfoDTO;
import com.easylinkin.linkappapi.grid.models.dto.GridQrDTO;
import com.easylinkin.linkappapi.grid.models.dto.GridUserDTO;
import com.easylinkin.linkappapi.grid.service.IGridInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestMessage;
import site.morn.validate.group.Add;
import site.morn.validate.group.Update;


/**
 * 网格信息表 前端控制器
 *
 * @author
 * @since 2024-05-15
 */
@Api(tags = "网格信息表")
@RestController
@RequestMapping("/grid/gridInfo")
public class GridInfoController {
    @Autowired
    private IGridInfoService gridInfoService;

    /**
     * 保存
     *
     * @param gridInfo
     * @return
     */
    @ApiOperation(value = "新增网格", notes = "新增网格", httpMethod = "POST")
    @PostMapping(value = "/save")
    public RestMessage save(@Validated(Add.class) @RequestBody GridInfoDTO gridInfo) {
        return this.gridInfoService.addGridInfo(gridInfo);
    }

    /**
     * 修改网格
     *
     * @param gridInfo
     * @return
     */
    @ApiOperation(value = "修改网格", notes = "修改网格", httpMethod = "POST")
    @PostMapping(value = "/update")
    public RestMessage update(@Validated(Update.class) @RequestBody GridInfoDTO gridInfo) {
        return this.gridInfoService.updateGridInfo(gridInfo);
    }


    /**
     * 通过id查询
     *
     * @return
     */
    @ApiOperation(value = "通过所有网格信息", notes = "通过所有网格信息", httpMethod = "GET")
    @GetMapping(value = "/queryInfo")
    public RestMessage queryInfo() {
        return gridInfoService.queryInfo();
    }

    @ApiOperation(value = "获取网格下拉框数据", notes = "获取网格下拉框数据", httpMethod = "GET")
    @GetMapping(value = "/querySelect")
    public RestMessage querySelect() {
        return gridInfoService.querySelect();
    }

    @ApiOperation(value = "通过ID网格信息", notes = "通过ID网格信息", httpMethod = "GET")
    @GetMapping(value = "/queryInfoById")
    public RestMessage queryInfoById(@RequestParam("id") String id) {
        return this.gridInfoService.queryInfoById(id);
    }

    @ApiOperation(value = "配置网格用户", notes = "配置网格用户", httpMethod = "POST")
    @PostMapping(value = "/configUser")
    public RestMessage configUser(@Validated @RequestBody GridUserDTO gridUserDTO) {
        return gridInfoService.configUser(gridUserDTO);
    }

    @ApiOperation(value = "配置网格二维码", notes = "配置网格二维码", httpMethod = "POST")
    @PostMapping(value = "/configQr")
    public RestMessage configQr(@Validated @RequestBody GridQrDTO gridQrDTO) {
        return gridInfoService.configQr(gridQrDTO);
    }

    @ApiOperation(value = "获取网格用户下拉框数据", notes = "获取网格用户下拉框数据", httpMethod = "GET")
    @GetMapping(value = "/queryGridUserSelect")
    public RestMessage queryGridUserSelect(@RequestParam(value = "gridId",defaultValue = "")Integer gridId) {
        return gridInfoService.queryGridUserSelect(gridId);
    }

    @ApiOperation(value = "删除网格用户", notes = "删除网格用户", httpMethod = "POST")
    @GetMapping(value = "/delUser/{id}")
    public RestMessage delUser(@PathVariable("id")Integer id) {
        return gridInfoService.delUser(id);
    }

    @ApiOperation(value = "删除网格", notes = "删除网格", httpMethod = "GET")
    @GetMapping(value = "/del/{id}")
    public RestMessage del(@PathVariable("id")Integer id) {
        return gridInfoService.del(id);
    }
}
